package com.example.fitnessservice.api.web;

import com.example.fitnessservice.module.pojo.CourseDetails;
import com.example.fitnessservice.module.pojo.CourseDetailsCamp;
import com.example.fitnessservice.module.pojo.Place;
import com.example.fitnessservice.module.pojo.Result;
import com.example.fitnessservice.service.PlaceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/place")
public class PlaceController {

    @Autowired
    private PlaceService placeService;

    /**
     * 修改场馆的营业时间
     * @param place
     * @return
     */
    @PutMapping
    public Result updatePlaceTime(@RequestBody Place place){
        boolean flag = placeService.updatePlaceTime(place.getId(), place.getStartTime(), place.getEndTime());

        Result result = new Result();
        if (flag){
            result.setCode(200);
            result.setMsg("修改场馆营业时间成功");
        }else {
            result.setCode(500);
            result.setMsg("修改场馆营业时间失败");
        }
        return result;
    }

    /**
     * 根据场馆的id，查询场馆下有哪些课程
     * @param placeId
     * @return
     */
    @GetMapping("/{placeId}")
    public Result findCourseInPlace(@PathVariable Integer placeId){
        List<CourseDetails> courses = placeService.findCourseInPlace(placeId);

        Result result = new Result();
        if(result != null){
            result.setCode(200);
            result.setMsg("课程查询成功");
            result.setData(courses);
        }else {
            result.setCode(500);
            result.setMsg("课程查询失败");
        }
        return result;
    }

    /**
     * 根据场馆id，查询场馆下有哪些训练营
     * @param placeId
     * @return
     */
    @GetMapping("/camp/{placeId}")
    public Result findCampInPlace(@PathVariable Integer placeId){
        List<CourseDetailsCamp> courseDetailsCamps = placeService.findCampInPlace(placeId);

        Result result = new Result();
        if(result != null){
            result.setCode(200);
            result.setMsg("训练营查询成功");
            result.setData(courseDetailsCamps);
        }else {
            result.setCode(500);
            result.setMsg("训练营查询失败");
        }
        return result;
    }


}
